/*============ This estimates App Fig 2: event study using BMS cont (spec=4) for the 8 demographic groups (dem =1 to 8) ===========*/

use "${data1}regready_cps_ipums_84.dta", clear

replace eitc = eitc*eitc_ref

local stat summstat(N)


local append outreg, merge(r) starloc(1) var stats(b se) blankrow  merge starlevels(10 5 1) bdec(3) `stat'  keep(tobacco21_treated ) nolegend




local  dem i.dem_race##i.post2002  i.dem_race#i.pre1988 i.dem_married i.dem_famsize ///
i.dem_nchild i.dem_nchild##i.pre1988 i.dem_educ i.dem_female i.dem_hisp##i.post2002

local  a1 year i.state_fips
local  a2 year i.state_fips `dem'
local  a3 year i.state_fips `dem'
local  a4 year i.state_fips `dem'
local  a5 year i.state_fips `dem'

local rhs1
local rhs2 age_* 
local rhs3 age_* ur_high_edu wage_high_edu hpi
local rhs4 age_* ur_high_edu wage_high_edu hpi eitc tanf4 snap4 ACA
local rhs5 age_* eitc_dube ur gdppc

local primary

local j .5
local thresholdlist 0.50(0.25)1.75
local thresholdlist 0.50(0.25).75
local thresholdlist 2
local thresholdlist .5  1 1.5 2 3 4
replace EF1 = 0
local dems es1 es2 es3 es4 es5 dem2 dem3 dem4 dem5 dem6
local d 5
local thresholdlist 2
local thresholdlist .5 1 1.5 2 3
local thresholdlist  1



foreach j of numlist `thresholdlist' {
forvalues d = 1/1 {
    forvalues spec = 4/5 {
  if `spec' ==5  replace contpov = contpov_dube
  /*if `spec' ==5 drop if year>2013*/
  
  cap drop under
  g  under = contpov < `j'
  local q = `j' * 100
  di "Poverty threshold `q'"
  if `d' == 5 reg under EF* EL* `rhs`spec'' `a`spec'' [pw=asecwt] if dem`d'==1,  cluster(state_fips)
  else reghdfe under EF* EL* `rhs`spec''  [pw=asecwt] if dem`d'==1, a(`a`spec'') cluster(state_fips)
  est save "${est}ster84/es_`q'_dem`d'_s`spec'", replace
  }
}
}


local j 2
local spec 5
    forvalues d = 1/1 {
  forvalues spec = 4/4 {
  foreach j of numlist 1(1)8 {
  
  
  cap drop under
  g  under = contpov < `j'
  local q = `j' * 100
  di "Poverty threshold `q'"
  if "`d'"=="1" local lab "Non-Elderly, < 65"
  if "`d'"=="2" local lab "All Ages, Including Elderly"
  if "`d'"=="3" local lab "Working Age Adults, Ages 16-64"
  if "`d'"=="4" local lab "≤ HS Degree, Ages 16-64"
  if "`d'"=="5" local lab "< HS Degree, Ages 16-24"
  if "`d'"=="6" local lab "Single Mothers, Ages 16-49"
  if "`d'"=="7" local lab "Black or Hispanic, Ages 16-64"
  if "`d'"=="8" local lab "Children Under Age 16"

  local range yla(-0.05(0.025)0.05)

  estimates use ${est}ster84/es_`q'_dem`d'_s`spec'
  est store D
  		coefplot ///
  			(D, omitted keep(EF* EL*)  msize(small) recast(connected) lcolor(gs1) color(gs1) lwidth(thin) ciopts(recast(rcap)  lcolor(gs10) lwidth(thin))),  ///
  			vertical xline(3.5) yline(0) graphregion(color(white)) yla(, nogrid) ///
  		   `range' ///
         legend(off) nooffsets ///
  			///title("`lab', ITN<`j'" , color(black))  /// "spec `spec'"
  			ytitle("Estimated Effect of Change in Minimum Wage") xtitle("Years Since Minimum Wage Increase")
  		graph export "${fig}event_studies/es84/es_`q'_dem`d'_s`spec'.png", replace

  }
}
}
